{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import sys\n",
    "# option to import from github folder\n",
    "sys.path.insert(0, 'C:/Users/carse/github/suite2p/')\n",
    "from suite2p import run_s2p\n",
    "\n",
    "# set your options for running\n",
    "ops = run_s2p.default_ops() # populates ops with the default options"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# provide an h5 path in 'h5py' or a tiff path in 'data_path'\n",
    "# db overwrites any ops (allows for experiment specific settings)\n",
    "db = {\n",
    "      'h5py': [], # a single h5 file path\n",
    "      'h5py_key': 'data',\n",
    "      'look_one_level_down': False, # whether to look in ALL subfolders when searching for tiffs\n",
    "      'data_path': ['C:/Users/carse/github/tiffs'], # a list of folders with tiffs \n",
    "                                             # (or folder of folders with tiffs if look_one_level_down is True, or subfolders is not empty)\n",
    "                                            \n",
    "      'subfolders': [], # choose subfolders of 'data_path' to look in (optional)\n",
    "      'fast_disk': 'C:/BIN', # string which specifies where the binary file will be stored (should be an SSD)\n",
    "    }\n",
    "\n",
    "# run one experiment\n",
    "opsEnd=run_s2p.run_s2p(ops=ops,db=db)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# make a list of db's and loop over them\n",
    "db = []\n",
    "db.append({'data_path': ['C:/Users/carse/github/tiffs']})\n",
    "db.append({'data_path': ['C:/Users/carse/github/tiffs2']})\n",
    "\n",
    "for dbi in db:\n",
    "    opsEnd=run_s2p.run_s2p(ops=ops,db=dbi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# only run on specified tiffs\n",
    "db = {\n",
    "      'h5py': [], # a single h5 file path\n",
    "      'h5py_key': 'data',\n",
    "      'look_one_level_down': False, # whether to look in ALL subfolders when searching for tiffs\n",
    "      'data_path': ['C:/Users/carse/github/tiffs/'], \n",
    "                    # a list of folders with tiffs \n",
    "                    # (or folder of folders with tiffs if look_one_level_down is True, or subfolders is not empty)        \n",
    "      'subfolders': [], # choose subfolders of 'data_path' to look in (optional)\n",
    "      'fast_disk': 'C:/BIN', # string which specifies where the binary file will be stored (should be an SSD)\n",
    "      'tiff_list': ['file022.tif', 'file023.tif'] # list of tiffs in folder * data_path *!\n",
    "    }\n",
    "\n",
    "\n",
    "# run one experiment\n",
    "opsEnd=run_s2p.run_s2p(ops=ops,db=db)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# make a list of all files in your folder (starting with 73.)\n",
    "### *** this is for files that don't end with *.tif or *.tiff ***\n",
    "\n",
    "import glob, os\n",
    "froot = '/media/carsen/DATA2/grive/suite2p_test/example-tiffs-metafluor/'\n",
    "files = glob.glob(os.path.join(froot, \"73.*\"))\n",
    "for n,f in enumerate(files):\n",
    "    files[n] = os.path.basename(f)\n",
    "    \n",
    "db = {\n",
    "      'h5py': [], # a single h5 file path\n",
    "      'h5py_key': 'data',\n",
    "      'look_one_level_down': False, # whether to look in ALL subfolders when searching for tiffs\n",
    "      'data_path': [froot], \n",
    "                            # a list of folders with tiffs \n",
    "                            # (or folder of folders with tiffs if look_one_level_down is True, or subfolders is not empty)\n",
    "                            \n",
    "      'subfolders': [], # choose subfolders of 'data_path' to look in (optional)\n",
    "      'tiff_list': files # list of tiffs in folder * data_path *!\n",
    "    }\n",
    "\n",
    "\n",
    "# run one experiment\n",
    "opsEnd=run_s2p.run_s2p(ops=ops,db=db)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## change the save directory from 'suite2p' to a chosen name\n",
    "# note the fast_disk will always be in 'suite2p', just the save_path will change\n",
    "\n",
    "ops = run_s2p.default_ops() # populates ops with the default options\n",
    "ops['sparse_mode'] = 1\n",
    "ops['threshold_scaling'] = 3.0\n",
    "db = {\n",
    "      'h5py': [], # a single h5 file path\n",
    "      'h5py_key': 'data',\n",
    "      'look_one_level_down': False, # whether to look in ALL subfolders when searching for tiffs\n",
    "      'data_path': ['D:/DATA/GT1/singlechannel_half/'], # a list of folders with tiffs \n",
    "                # (or folder of folders with tiffs if look_one_level_down is True, or subfolders is not empty)\n",
    "      'save_folder': 'suite2p_sparse_mode'\n",
    "    }\n",
    "\n",
    "# run one experiment\n",
    "opsEnd=run_s2p.run_s2p(ops=ops,db=db)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# h5py file with multiple data fields (untested)\n",
    "\n",
    "ops = run_s2p.default_ops() # populates ops with the default options\n",
    "ops['nplanes'] = 12\n",
    "ops['nchannels'] = 2\n",
    "ops['fs'] = 5.0\n",
    "\n",
    "db = {\n",
    "      'h5py': 'C:/Users/carse/H5/data1.h5', # a single h5 file \n",
    "      'h5py_key': ['data'], # list of keys to use (they will be extracted in the order you give them)\n",
    "      'look_one_level_down': True, # for h5 files, whether to use all files in same folder\n",
    "      'data_path': [] # keep this empty!\n",
    "    }\n",
    "\n",
    "# run one experiment\n",
    "opsEnd=run_s2p.run_s2p(ops=ops,db=db)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
